package com.bolt.support.spring.jpa.transform;

import com.bolt.support.query.toolkit.JPAUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.transform.ResultTransformer;

import java.util.Arrays;
import java.util.List;

public class RecordMapperTransform implements ResultTransformer {

    protected final Log logger = LogFactory.getLog(getClass());

    public static final RecordMapperTransform INSTANCE = new RecordMapperTransform();


    private RecordMapperTransform() {
    }

    @Override
    public Object transformTuple(Object[] tuple, String[] aliases) {
        if (tuple != null) {
            return JPAUtil.toRecord(tuple, Arrays.asList(aliases));
        } else {
            return null;
        }
    }

    @Override
    public List transformList(List collection) {
        return collection;
    }
}